package fe.bmsearch.gui.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;

public class DocumentDetail extends ResizeComposite  implements SelectedDocumentListener {

	private static DocumentDetailUiBinder uiBinder = GWT
			.create(DocumentDetailUiBinder.class);

	interface DocumentDetailUiBinder extends UiBinder<Widget, DocumentDetail> {
	}
	
	  @UiField Element headline;
	  @UiField Element uid;
	  @UiField HTML body;

	public DocumentDetail() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	 


	@Override
	public void onSelectedDocument(String dataType, String ruid) {
		GetDocumentServiceAsync service=GWT.create(GetDocumentService.class);
		
		final AsyncCallback<DocumentItem> getDocumentCB
		= new AsyncCallback<DocumentItem>() {

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Error: " + caught.getMessage());
			}

			@Override
			public void onSuccess(DocumentItem doc) {
				headline.setInnerText(doc.headline);
				uid.setInnerText(doc.uid);
				body.setHTML(doc.body);
			
			}	
		};
		
		service.getDocumentItem(dataType, ruid, getDocumentCB);
		
	}

}
